//
//  badgeUrl.m
//  EcmDoctor
//
//  Created by zhm on 16/3/8.
//  Copyright © 2016年 张进. All rights reserved.
//

#import "badgeUrl.h"
#import "NetWorkUtil.h"
#import <SSKeychain/SSKeychain.h>
#import "AppUtils.h"

@implementation badgeUrl

+(void)badgeWithdoctor_info_id:(NSString *)doctor_info_id moduleName:(NSString *)moduleName methodname:(NSString *)methodname success:(void (^)(NSString *)) success failure:(void (^)(NSError *))failure {
    NetWorkBaseRequest *req = [[NetWorkBaseRequest alloc] init];
    //请求参数
    
    req.moduleName = moduleName;
    req.methodName = methodname;
    [req setValue:doctor_info_id forKey:@"doctor_info_id"];
    
    [NetWorkUtil requestWithPOST:req success:^(NetWorkBaseResponse *responseObject) {
        NSError *error = nil;
        
        if (responseObject.code.integerValue == 1) {
            if (!responseObject.data) {
                success(nil);
                return;
            }
            
            NSData *data = [responseObject.data dataUsingEncoding:NSUTF8StringEncoding];
            NSString *userAttrs = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
            
            if (userAttrs == nil) {
                success(@"");
                return;
            }
            
            if (error) {
                failure(error);
                return;
            }
            
            success(userAttrs);
            
        } else{
            error = [NSError errorWithDomain:responseObject.msg code:responseObject.code.integerValue userInfo:nil];
            failure(error);
        }
        
    } failure:^(NSError *error) {
        failure(error);
        
    } cache:NO];
}

+(void)updateOnLineStateWithmethodname:(NSString *)methodname andask_info_id:(NSString *)ask_info_id success:(void (^)(BOOL))success failure:(void (^)(NSError *))failure {

    NetWorkBaseRequest *req = [[NetWorkBaseRequest alloc] init];
    //请求参数
    
    req.moduleName = @"DoctorRS";
    req.methodName = methodname;
    [req setValue:[SSKeychain passwordForService:APP_SERVICE_NAME account:APP_DOCTORINFOID_KEY] forKey:@"doctor_info_id"];
    [req setValue:ask_info_id forKey:@"ask_info_id"];
    
    [NetWorkUtil requestWithPOST:req success:^(NetWorkBaseResponse *responseObject) {
        NSError *error = nil;
        
        if (responseObject.code.integerValue == 1) {
            
            success(YES);
            
        } else {
            
            error = [NSError errorWithDomain:responseObject.msg code:responseObject.code.integerValue userInfo:nil];
            failure(error);
        }
        
    } failure:^(NSError *error) {
        failure(error);
        
    } cache:NO];
}

@end
